package com.itheima.mall.service.PmsService;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mall.mapper.PmsMapper.PmsSkuStockMapper;
import com.itheima.mall.service.pmsService.PmsSkuStockApi;
import com.itheima.pojo.pms.PmsSkuStock;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsSkuStockApiImpl implements PmsSkuStockApi {


    @Autowired
    private PmsSkuStockMapper pmsSkuStockMapper;

    @Override
    public List<PmsSkuStock> searchSku(Long pid, String keyword) {
        LambdaQueryWrapper<PmsSkuStock> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(pid != null,PmsSkuStock::getProductId,pid);
        queryWrapper.like(keyword != null,PmsSkuStock::getSkuCode,keyword);
        return pmsSkuStockMapper.selectList(queryWrapper);
    }

    @Override
    public void updateSku(Long pid, PmsSkuStock pmsSkuStock) {
        LambdaQueryWrapper<PmsSkuStock> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(pid != null,PmsSkuStock::getProductId,pid);
        pmsSkuStockMapper.update(pmsSkuStock,queryWrapper);
    }
}
